#include <event2/event.h>
#include <event2/listener.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#define SPORT 9005

void listen_cb(struct evconnlistener *, evutil_socket_t, struct sockaddr *, int socklen, void *)
{
    printf("listen_cb\r\n");
}

int main() {
    if(signal(SIGPIPE, SIG_IGN) == SIG_ERR){
        return 1;
    }
    event_base * base = event_base_new();
    if(base) {
        printf("event_base_new success!\r\n");
    }
    /* socket, bind, listen*/
    sockaddr_in sin;
    memset(&sin, 0, sizeof(sin));
    sin.sin_family = AF_INET;
    sin.sin_port = htons(SPORT);
    evconnlistener *ev = evconnlistener_new_bind(base,/*base*/
                        listen_cb,
                        base,
                        LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_FREE,
                        10,
                        (sockaddr*)&sin,
                        sizeof(sin));
    /*事件分发处理*/
    event_base_dispatch(base);
    

    evconnlistener_free(ev);
    event_base_free(base);
}